package com.yixin.hospital.controller;

import com.yixin.hospital.common.ApiResult;
import com.yixin.hospital.common.Constant;
import com.yixin.hospital.entity.domain.Menu;
import com.yixin.hospital.service.MenuService;
import com.yixin.hospital.utils.JwtUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/menu")
@Api(value = "菜单管理", tags = "菜单管理")
public class MenuController {

    @Resource
    private MenuService menuService;

    @GetMapping("/list")
    @ApiOperation(value = "菜单列表")
    public ApiResult list() {
        List<Menu> list = menuService.list();
        return ApiResult.success(list);
    }

    @GetMapping("/tree-list")
    @ApiOperation(value = "菜单列表（树）")
    public ApiResult listTree() {
        return menuService.treeList();
    }

    @GetMapping("/user-menus")
    @ApiOperation(value = "菜单列表 by token")
    public ApiResult listTree(HttpServletRequest request) {
        Long userId = JwtUtil.getUserId(request.getHeader(Constant.AUTHORIZATION));
        return menuService.userMenus(userId);
    }

    @GetMapping("/user-menus/{userId}")
    @ApiOperation(value = "用户拥有的菜单列表")
    public ApiResult userMenus(@PathVariable int userId) {
        return menuService.userMenusByUserId(userId);
    }

    @GetMapping("/user-menus-by-jobDuty/{jobDutyId}")
    @ApiOperation(value = "职务拥有得菜单列表")
    public ApiResult jobDutyMenus(@PathVariable int jobDutyId) {
       return menuService.jobDutyMenusByJobDutyId(jobDutyId);
    }

}
